package ces.lawsuit.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ces.lawsuit.model.User;
import ces.lawsuit.util.App;

public class LoginController extends BaseController<User> {
	/**注册登陆名时,必须验证唯一性*/
  public void doLogin(){
	User user=getModel(User.class);
	List<User> userList=  User.me.find(User.LOGIN_SQL, user.get("loginName"));
	Map<String,String> returnMap=new HashMap();
	if(userList.isEmpty()){
		returnMap.put("statusCode", "300");
		returnMap.put("message", "登陆用户名不存在!");
		renderJson(returnMap);
	}else {
		User loginUser=userList.get(0);
		if(loginUser.get("password").equals(user.get("password"))){
			getSession().setAttribute(App.USER_SESSION_KEY, loginUser);
			render("/common/index.html");
			
		}else{
			returnMap.put("statusCode", "300");
			returnMap.put("message", "密码错误!");
			renderJson(returnMap);
		}
		
	}
  }
  public void index(){
	  render("/common/login.html");
  }
}
